yepnope.errorTimeout = 2000;
yepnope([
    {

        // Load jQuery - try CDN first, fallback to local file

        load : '//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js',
        callback: function () {
            if (!window.jQuery) {
                yepnope('/textpattern5/admin/js/jquery.js'); // TODO: change to proper paths in final build
            }
        }

	}, {

        // Load other essential JavaScript files and execute

        load: [ // TODO: change to proper paths in final build
                '/textpattern5/admin/js/jquery.formalize.min.js',
                '/textpattern5/admin/js/jquery.DOMWindow.js',
                '/textpattern5/admin/js/bootstrap-alerts.js',
                '/textpattern5/admin/js/bootstrap-dropdown.js',
                '/textpattern5/admin/js/bootstrap-tabs.js'
        ],
        complete: function () { // start DOM ready
            jQuery(function () {


                // To make select navigation menu work
                $('nav select').change(function() {
                    window.location = $(this).find('option:selected').val();
                });


                // External links open new window (target="_blank" replacement)
                $('[rel="external"]').click( function() {
                    window.open( $(this).attr('href') );
                    return false;
                });


                // Modals - inline content
                $('.modal-inline').openDOMWindow({
                    eventType:'click'
                });


                // Modals - ajax content
                $('.modal-ajax').openDOMWindow({
                    eventType:'click',
                    windowSource:'ajax',
                    windowHTTPType:'post'
                });


                // Modals - iframe content
                $('.modal-iframe,[rel="help"]').openDOMWindow({
                    eventType:'click',
                    windowSource:'iframe'
                });


                // Accordions
                $('legend a.dropdown-toggle').click(function() {
                    if($(this).hasClass('dropdown-toggle-open')){
                        $(this).removeClass('dropdown-toggle-open');
                        $(this).parent().next('.dropdown-pane').slideUp('fast');
                    }else{
                        $('legend a.dropdown-toggle').removeClass('dropdown-toggle-open');
                        $(this).addClass('dropdown-toggle-open');
                        $(this).parent().next('.dropdown-pane').slideDown('fast');
                    }
                    return false;
                });


            });
        } // end DOM ready

    }, {

        // Test for date input support (use jQuery UI datepicker as a fallback)

        test: (function() {
            var elem = document.createElement('input');
            elem.setAttribute('type', 'date');
            return elem.type === 'date';
        })(),
        nope: '/textpattern5/admin/js/jquery-ui-datepicker.js', // TODO: change to proper paths in final build
        callback: function() { // start DOM ready
            $('[type="date"]').datepicker({
                dateFormat: 'yy-mm-dd'
            });
        } // end DOM ready

    }
]);
